<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="../plugins/jquery/jquery-3.2.1.min.js" type="text/javascript"></script>
</head>
<body>
	<input type="file" onchange="upload()" style="display:none" id="file-input" />
	<button onclick='selectFile()'>上传</button>

	<script>
		var inputBox = document.getElementById("file-input");
		
		function selectFile(){
			inputBox.click()
		}		
		function upload(){
			var file = inputBox.files[0]
			if(! file){
				alert('请选择文件')
				return
			}
			var form = new FormData()
			form.append('file',file)
			var xhr = new XMLHttpRequest();
            xhr.open("post", '../../api/receiveOptionQuestion', true);      
            xhr.onload = function () {   
                alert(xhr.responseText);
            };
            xhr.upload.addEventListener("progress", function(e){
            	console.log(e.loaded / e.total * 100)
            }, false);
            xhr.send(form);
		}
		
		
	</script>
</body>
</html>